<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<!DOCTYPE HTML>
<html>
<head>
<base href="${pageContext.request.contextPath}/">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>新闻中国</title>
<link href="css/read.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
	  		function check(){
	  			var cauthor = document.getElementById("cauthor");
	  			var content = document.getElementById("ccontent");
	  			if(cauthor.value == ""){
	  				alert("用户名不能为空！！");
	  				return false;
	  			}else if(content.value == ""){
	  				alert("评论内容不能为空！！");
	  				return false;
	  			}
	  			return true;
	  		}
	  		function clickdel() {
				return confirm("删除请点击确认");
			}
</script>
<c:if test="${! empty mess }"> 
	<script>
		alert("${mess}");
	</script>
	<c:remove var="mess" scope="request"/>
</c:if>
</head>
<body>
<div id="header">
	<c:set var="isLogin" value="${empty user}" />
	<c:if test="${isLogin}">
		<div id="top_login">
			<form action="LoginServlet" method="post" onsubmit="return check()">
				<label> 登录名 </label>
				<input type="text" name="uname" id="uname" value="${param.uname}" class="login_input" />
				<label> 密&#160;&#160;码 </label>
				<input type="password" name="upwd" id="upwd" value="" class="login_input" />
				<input type="submit" class="login_sub" value="登录" />&#160;&#160;&#160;&#160;<a href="index.jsp">返回首页</a>
				<label id="error" style="color: red;">${mess}<c:remove var="mess" scope="request"/></label>
				<img src="images/friend_logo.gif" alt="Google" id="friend_logo" />
			</form>
		</div>
	</c:if>
	<c:if test="${!isLogin}">
		<h4>欢迎您&#160;${user.uname}&#160;&#160;&#160;&#160;<a href="AdminServlet">个人中心</a>&#160;&#160;&#160;&#160;<a href="LogoutServlet">login out</a>&#160;&#160;&#160;&#160;<a href="index.jsp">返回首页</a></h4>
	</c:if>
	<div id="nav">
		<div id="logo">
			<img src="images/logo.jpg" alt="新闻中国" />
		</div>
		<div id="a_b01">
			<img src="images/a_b01.gif" alt="" style="margin-top: 20px;"/>
		</div>
		<!--mainnav end-->
	</div>
</div>

<div id="container">
  <jsp:include page="include_elements/index_sidebar.jsp"></jsp:include>

  <div class="main">
    <div class="class_type"> <img src="images/class_type.gif" alt="新闻中心"/> </div>
    <div class="content">
      <ul class="classlist">
        <table width="80%" align="center">
          <tr width="100%">
            <td colspan="2" align="center">${news.ntitle}</td>
          </tr>
          <tr>
            <td colspan="2"><hr />
            </td>
          </tr>
          <tr>
            <td align="center">${news.nmodifyDate}</td>
            <td align="left">作者：${news.nauthor}</td>
          </tr>
          <tr>
            <td colspan="2" align="center"></td>
          </tr>
          <c:if test="${news.npicPath != null}">
        	  <tr>
	            <td colspan="2" align="center"><img alt="" src="${news.npicPath}" width="100%"></td>
	          </tr>
          </c:if>
          <tr>
            <td colspan="2">${news.ncontent}</tr>
          <tr>
            <td colspan="2"><hr />
            </td>
          </tr>
        </table>
      </ul>
      <ul class="classlist">
        <table width="80%" align="center" style="display: ${fn:length(comments)==0?'table':'none'}">
          <tr><td colspan="6"> 暂无评论！ </td></tr>
          <tr>
            <td colspan="6"><hr /></td>
          </tr>
        </table>
      </ul>
      <ul class="classlist">
        <form action="AddCommentServlet?cnid=${news.nid}" method="post" onsubmit="return check()">
          <table width="80%" align="center" style="display: ${fn:length(comments)==0?'none':'table'}">
            <tr>
              <td colspan="6"> 评 论 </td>
            </tr>
            <tr>
              <td colspan="6"><hr/></td>
            </tr>
            <c:forEach items="${comments}" var="comment">
            	<tr>
	              <td colspan="3" width="50%">${comment.ccontent}</td>
	              <td width="10%">${comment.cauthor}</td>
	              <td width="15%">${comment.cdate}</td>
	              <td width="5%"><a href='DelCommentServlet?nid=${news.nid}&cid=${comment.cid}' onclick='return clickdel()'>删除</a></td>
	            </tr>
	             <tr>
	              <td colspan="6"><hr/></td>
	            </tr>
            </c:forEach>
          </table>
          <table width="80%" align="center">
            <tr>
              <td> 用户名： </td>
              <td><input id="cauthor" type="text" name="cauthor" value="这家伙很懒什么也没留下"/>
                IP：
                <input name="cip" type="text" value="${pageContext.request.remoteAddr}" readonly="readonly"/>
              </td>
            </tr>
            <tr>
              <td colspan="2"><textarea name="ccontent" cols="70" rows="10"></textarea>
              </td>
            </tr>
            <tr>
              <td><input name="submit" value="发  表" type="submit"/>
              </td>
             </tr>
          </table>
        </form>
      </ul>
    </div>
  </div>
</div>
<div id="footer">
  <div id="site_link"> <a href="#">关于我们</a><span>|</span> <a href="#">Aboue Us</a><span>|</span> <a href="#">联系我们</a><span>|</span> <a href="#">广告服务</a><span>|</span> <a href="#">供稿服务</a><span>|</span> <a href="#">法律声明</a><span>|</span> <a href="#">招聘信息</a><span>|</span> <a href="#">网站地图</a><span>|</span> <a href="#">留言反馈</a> </div>
  <jsp:include page="include_elements/bottom.jsp"></jsp:include>
</div>
</body>
</html>
